﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COM.Rights.Model;
using COM.Rights.BLL;

public partial class FrontPages_UserControl_NewsDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            //InitNewsDetail("");
        }
    }

    public string StyleName
    {
        get
        {
            return CssControler.GetCssFileNameByHost(HostName);
        }
    } 

    private string _HostName;
    public string HostName
    {
        get
        {
            if (StringHelper.FormatObjToString(ViewState["HostName"]) != string.Empty)
            {
                return StringHelper.FormatObjToString(ViewState["HostName"]);
            }
            else if (!string.IsNullOrEmpty(hidHostName.Value))
            { ViewState["HostName"] = hidHostName.Value; return hidHostName.Value; }

            return this._HostName;
        }
        set
        {
            ViewState["HostName"] = value;
        }
    }

 

    public void InitNewsDetail(string NewsID)
    {
        //NewsID = "08D81C4E-FDC7-F4E3-464E-36022B129919";
        if (string.IsNullOrEmpty(NewsID)) { return; }
        BdNews _BdNews = new BdNews();
        BdNewsInfo _BdNewsInfo = _BdNews.GetModel("NewsTitle,PublishDate,Contents",  string.Format(" HostName LIKE '%{0}%' AND IsDelete = 0 AND NEWS_ID='{1}'",HostName,NewsID) , "", new List<DBParameter>());
      
     
        {
            this.litTitle.Text = _BdNewsInfo.NewsTitle;
            this.litNewsDate.Text = _BdNewsInfo.PublishDate.ToString();
            this.litNewsContent.Text = _BdNewsInfo.Contents;
        }

        List<BdNewsInfo> _Last = _BdNews.GetTop(1, "News_ID,NewsTitle", "PublishDate >='" + _BdNewsInfo.PublishDate.ToString() + "' AND News_ID != '" + NewsID + "'", " PublishDate  ", new List<DBParameter>());
        string referURL = Request.Url.ToString();
        referURL = referURL.Substring(0, referURL.IndexOf("?") == -1 ? referURL.Length : referURL.IndexOf("?"));
        if (_Last != null && _Last.Count >0  )
        {
            BdNewsInfo bd = _Last[0];
            this.PreNews.HRef = string.Format(referURL+"?ID={0}", bd.News_ID);
            this.PreNews.InnerHtml = "上一篇：" + bd.NewsTitle;
        }
        else
        {
            this.PreNews.InnerHtml = "上一篇：没有了";
        }

        List<BdNewsInfo> _next = _BdNews.GetTop(1, "News_ID,NewsTitle", "PublishDate <='" + _BdNewsInfo.PublishDate.ToString() + "' AND News_ID != '" + NewsID + "'", " PublishDate DESC ", new List<DBParameter>());
        if (_next != null && _next.Count > 0)
        {
            BdNewsInfo bd = _next[0];
            this.NextNews.HRef = string.Format(referURL + "?ID={0}", bd.News_ID);
            this.NextNews.InnerHtml = "下一篇：" + bd.NewsTitle;
        }
        else
        {
            this.NextNews.InnerHtml = "下一篇：没有了";
        }
    }


}